//package com.gitee.feizns.quickstart.utils.dingtalk.api;
//
//import com.dingtalk.api.DefaultDingTalkClient;
//import com.dingtalk.api.DingTalkClient;
//import com.dingtalk.api.request.OapiEduDeptGetRequest;
//import com.dingtalk.api.request.OapiEduDeptListRequest;
//import com.dingtalk.api.request.OapiEduUserGetRequest;
//import com.dingtalk.api.request.OapiEduUserListRequest;
//import com.dingtalk.api.response.OapiEduDeptGetResponse;
//import com.dingtalk.api.response.OapiEduDeptListResponse;
//import com.dingtalk.api.response.OapiEduUserGetResponse;
//import com.dingtalk.api.response.OapiEduUserListResponse;
//import com.gitee.feizns.quickstart.utils.dingtalk.api.v10.oauth2.AccessToken;
//import com.gitee.feizns.quickstart.utils.dingtalk.oauth.V1OAuth2;
//import com.taobao.api.ApiException;
//import lombok.RequiredArgsConstructor;
//import lombok.SneakyThrows;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 家校通讯录相关接口
// * <b>教育模块钉钉api工具类</b>
// * <p>
// *     <a href="https://open.dingtalk.com/document/isvapp/overview-6">服务端API > 行业开放 > 新教育 > 概述</a>
// * </p>
// * @author feizns
// * @since 2023/2/14
// */
//@RequiredArgsConstructor
//public class EduUtils {
//
//    /**
//     * {@link AccessToken}
//     */
//    private final AccessToken accessToken = ;
//
//    /**
//     * 家校通讯录部门相关api
//     */
//    private final DeptApi deptApi = new DeptApi();
//
//    /**
//     * 用户接口
//     */
//    private final UserApi userApi = new UserApi();
//
//    /**
//     * 服务端API > 行业开放 > 新教育 > 家校通讯录2.0 > 部门管理
//     * @return {@link DeptApi}
//     */
//    public DeptApi dept() {
//        return deptApi;
//    }
//
//    /**
//     * 服务端API > 行业开放 > 新教育 > 家校通讯录2.0 > 用户管理
//     * @return {@link DeptApi}
//     */
//    public UserApi user() {
//        return userApi;
//    }
//
//    /**
//     * 服务端API > 行业开放 > 新教育 > 家校通讯录2.0
//     * @author feizns
//     * @since 2023/09/13
//     */
//    public class DeptApi {
//
//        /**
//         * <a href="https://open.dingtalk.com/document/isvapp/obtains-the-department-node-list">获取部门列表</a>
//         * {@link OapiEduDeptListResponse.OpenEduDeptDetails}
//         * @param superId super编号
//         * @return {@link List}<{@link OapiEduDeptListResponse.OpenEduDeptDetails}>
//         */
//        @SneakyThrows
//        public List<OapiEduDeptListResponse.OpenEduDeptDetails> list(Long superId) {
//            List<OapiEduDeptListResponse.OpenEduDeptDetails> resultList = new ArrayList<>();
//            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/edu/dept/list");
//            final long maxPageSize = 30L;
//            long pageNo = 1L;
//            OapiEduDeptListResponse.OpenEduDeptListResponse result;
//            do {
//                OapiEduDeptListRequest req = new OapiEduDeptListRequest();
//                req.setPageSize(maxPageSize);
//                req.setPageNo(pageNo);
//                if ( superId != null )
//                    req.setSuperId(superId);
//                OapiEduDeptListResponse rsp = client.execute(req, v1OAuth2.accessToken().get());
//                if ( !rsp.isSuccess() )
//                    throw new RuntimeException("错误码：" + rsp.getErrorCode() + " 错误消息：" + rsp.getErrmsg());
//                result = rsp.getResult();
//                pageNo++;
//                resultList.addAll(result.getDetails());
//            } while ( result.getHasMore() );
//            return resultList;
//        }
//
//        /**
//         * 获取部门详情
//         * teacher：老师
//         * guardian：监护人
//         * student：学生
//         * @link <a href="https://open.dingtalk.com/document/isvapp/obtains-queries-department-details">获取部门详情</a>
//         * @param deptId 部门编号
//         * @return {@link OapiEduDeptGetResponse.OpenEduDeptDetail}
//         */
//        @SneakyThrows
//        public OapiEduDeptGetResponse.OpenEduDeptDetail get(Long deptId) {
//            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/edu/dept/get");
//            OapiEduDeptGetRequest req = new OapiEduDeptGetRequest();
//            req.setDeptId(deptId);
//            OapiEduDeptGetResponse resp = client.execute(req, v1OAuth2.accessToken().get());
//            if ( !resp.isSuccess() )
//                throw new RuntimeException("错误码：" + resp.getErrorCode() + " 错误消息：" + resp.getErrmsg());
//            return resp.getResult().getDetail();
//        }
//
//    }
//
//    /**
//     * 服务端API > 行业开放 > 新教育 > 家校通讯录2.0 > 用户管理
//     * @author feizns
//     * @since 2023/09/13
//     */
//    public class UserApi {
//
//        /**
//         * 服务端API > 行业开放 > 新教育 > 家校通讯录2.0 > 获取人员列表
//         * @link <a href="https://open.dingtalk.com/document/isvapp/obtains-a-list-of-home-school-user-identities">获取人员列表</a>
//         * @param classId 班级编号 班级ID。
//         * 企业内部应用，调用获取部门列表接口获取dept_type为class时的dept_id参数值。
//         * 第三方企业应用，调用获取部门列表接口获取dept_type为class时的dept_id参数值。
//         * @param role 角色 家校人员角色。
//         * teacher：老师
//         * guardian：监护人
//         * student：学生
//         * @return {@link OapiEduUserListResponse.OpenEduUserDetail}
//         */
//        public List<OapiEduUserListResponse.OpenEduUserDetail> list(Long classId, String role) throws ApiException {
//            List<OapiEduUserListResponse.OpenEduUserDetail> resultList = new ArrayList<>();
//            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/edu/user/list");
//            final long maxPageSize = 30L;
//            long pageNo = 1L;
//            OapiEduUserListResponse.Result result;
//            do {
//                OapiEduUserListRequest req = new OapiEduUserListRequest();
//                req.setPageSize(maxPageSize);
//                req.setPageNo(pageNo);
//                req.setRole(role);
//                req.setClassId(classId);
//                OapiEduUserListResponse rsp = client.execute(req, v1OAuth2.accessToken().get());
//                if ( !rsp.isSuccess() )
//                    throw new RuntimeException("错误码：" + rsp.getErrorCode() + " 错误消息：" + rsp.getErrmsg());
//                result = rsp.getResult();
//                pageNo++;
//                resultList.addAll(result.getDetails());
//            } while (result.getHasMore());
//            return resultList;
//        }
//
//        /**
//         * 服务端API > 行业开放 > 新教育 > 家校通讯录2.0 > 获取人员详情
//         * @link <a href="https://open.dingtalk.com/document/isvapp/obtain-the-identity-details-of-home-school-personnel">获取人员详情</a>
//         * @param classId 班级编号
//         * @param role {@link String}
//         * @param userid 用户编号
//         * @return {@link OapiEduUserGetResponse}
//         */
//        @SneakyThrows
//        public OapiEduUserGetResponse.Result get(Long classId, String role, String userid) {
//            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/edu/user/get");
//            OapiEduUserGetRequest req = new OapiEduUserGetRequest();
//            req.setClassId(classId);
//            req.setRole(role);
//            req.setUserid(userid);
//            OapiEduUserGetResponse rsp;
//            rsp = client.execute(req, v1OAuth2.accessToken().get());
//            if ( !rsp.isSuccess() )
//                throw new RuntimeException("错误码：" + rsp.getErrorCode() + " 错误消息：" + rsp.getErrmsg());
//            return rsp.getResult();
//        }
//
//    }
//
////    /**
////     * 获取学生详情信息
////     * @param classId 班级编号
////     * @param studentUserid 学生编号
////     * @return {@link OapiEduClassStudentinfoGetResponse.OpenStudentSelectDto}
////     */
////    public OapiEduClassStudentinfoGetResponse.OpenStudentSelectDto getStudentInfo(Long classId, String studentUserid) {
////        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/edu/class/studentinfo/get");
////        OapiEduClassStudentinfoGetRequest req = new OapiEduClassStudentinfoGetRequest();
////        req.setAppId(v1OAuth2.getConfig().getAgentId());
////        req.setClassId(classId);
////        req.setUserid(studentUserid);
////        OapiEduClassStudentinfoGetResponse rsp;
////        try {
////            rsp = client.execute(req, v1OAuth2.getAccessToken());
////            if ( !rsp.isSuccess() )
////                throw new RuntimeException(rsp.getBody());
////
////            return rsp.getResult();
////        } catch (ApiException e) {
////            throw new RuntimeException(e);
////        }
////    }
////
////    /**
////     * <b>获取学生监护人详情</b>
////     * @link <a href="https://open.dingtalk.com/document/isvapp/obtain-the-relationship-between-home-and-school-personnel">获取学生监护人详情</a>
////     * @param classId 班级编号
////     * @param fromUserid 家长编号
////     * @return {@link OapiEduUserRelationGetResponse.Result}
////     */
////    public OapiEduUserRelationGetResponse.Result eduUserRelationGet(Long classId, String fromUserid) {
////        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/edu/user/relation/get");
////        OapiEduUserRelationGetRequest req = new OapiEduUserRelationGetRequest();
////        req.setFromUserid(fromUserid);
////        req.setClassId(classId);
////        OapiEduUserRelationGetResponse rsp;
////        try {
////            rsp = client.execute(req, v1OAuth2.getAccessToken());
////            if ( !rsp.isSuccess() )
////                throw new RuntimeException(rsp.getBody());
////            return rsp.getResult();
////        } catch (ApiException e) {
////            throw new RuntimeException(e);
////        }
////    }
////
//
//}
